package com.baidu.manager.modules.sys.redis;

import com.baidu.manager.common.utils.RedisUtils;
import com.baidu.manager.modules.sys.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: jql
 * @description: TODO()
 * @Date: Created by 16:18 2018/6/7
 */
@Component
public class SysUserRedis {

    private static final String NAME = "SysUser";

    @Autowired
    private RedisUtils redisUtils;

    public void saveOrUpdate(SysUser user){
        if (user == null){
            return;
        }

        String id = NAME + user.getId();
        redisUtils.set(id, user);

        String username = NAME + user.getUsername();
        redisUtils.set(username,user);
    }

    public void delete(SysUser user){
        if (user == null){
            return;
        }

        redisUtils.delete(NAME+user.getUsername());
        redisUtils.delete(NAME+user.getId());
    }

    public SysUser get(Object key) {
        return redisUtils.get(NAME+key,SysUser.class);
    }
}
